import it.gnocco.ann.NeuralNetwork;
import it.gnocco.grafics.Finestrella;
import java.io.File;
import it.gnocco.properties.*;
import it.gnocco.robotica.*;
import it.gnocco.state.Stato;
import it.gnocco.grafo.*;
import it.gnocco.log.*;
import java.awt.Color;

import java.util.*;

import com.heatonresearch.book.introneuralnet.neural.feedforward.FeedforwardNetwork;


public class Main {

	private static final String CLASS = "Main";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
		Property prop = new Property();
		Logger log = new Logger(prop);
		Logger.log(Logger.ERROR, CLASS, "main", "Loggo gli errori");
		Logger.log(Logger.WARNING, CLASS, "main", "Loggo pure i warning!");
		Logger.log(Logger.MESSAGE, CLASS, "main", "Loggo fin'anche i message!!");
		Logger.log(Logger.INFO, CLASS, "main", "Loggo anche le info!!!");
		Grafo g = new Grafo(prop);
		g.leggiGrafoDaFile(new File("grafo.csv"));
		RobotTeam rt = new RobotTeam(prop);
		Finestrella f = new Finestrella(g);
		rt.f = f;
		Stato s = rt.setStatoIniziale(g);

		ArrayList<Stato> STATO = new ArrayList<Stato>();
		STATO.add(s);
		rt.algoritmo(STATO, Integer.valueOf(prop.get("numero_prove")));
		rt.S.stampaStati();
		
		
		
		if(Boolean.valueOf(prop.get("usa_network"))){
			FeedforwardNetwork network = new NeuralNetwork().impara(rt.S, g.getSizeNodi(), rt.numero_robot);
			rt.vai(network);
		} else {
			rt.vai();
		}
		} catch (Exception ex){
			Logger.log(Logger.ERROR, CLASS, "main", ex.getMessage());
			for(int i = 0; i < ex.getStackTrace().length; i++)
				Logger.log(Logger.ERROR, ex.getStackTrace()[i].getClassName(), ex.getStackTrace()[i].getMethodName(), ex.getStackTrace()[i].toString());
		} catch (Error er){
			Logger.log(Logger.ERROR, CLASS, "main", er.getMessage());
			for(int i = 0; i < er.getStackTrace().length; i++)
				Logger.log(Logger.ERROR, er.getStackTrace()[i].getClassName(), er.getStackTrace()[i].getMethodName(), er.getStackTrace()[i].toString());
		}
	}
}
